﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MethodWorx.Core.DomainModel;

namespace MethodWorx.CMS.Content
{
    public class ContentItem : AggregateRoot
    {
        public ContentItem()
        {
            this.DateCreated = DateTime.Now;
            this.Status = ContentStatus.Unpublished;
        }

        public string Name { get; set; }
        public virtual ContentTemplate Template { get; set; }
        public virtual Page Page { get; set; }
        public bool Deleted { get; set; }
        public virtual PageProperty[] Properties { get; set; }
        public virtual PageProperty[] PublishedProperties { get; set; }
        public ContentStatus Status { get; set; }
        public DateTime DateCreated { get; set; }
        public DateTime? DatePublished { get; set; }
        public int Sequence { get; set; }

        public int CountLevelsUnderPage(Page page)
        {
            if(page == null)
                throw new ArgumentNullException("page");
            int level = 0;
            var parent = this.Page;
            while (parent != null)
            {
                if (parent == page)
                    return level;
                parent = parent.Parent;
                level++;
            }
            return -1;
        }
    }
}
